<?php

class OOWP_Atom_PostCategories
    extends OOWP_Formattable
{

    public function __construct(array $args = array( ))
    {
        $input = array_merge(array(
            'formatting' => 'Posted under %s',
        ), $args);

        parent::__construct($input);
    }

    protected function getFormatting( )
    {
        return $this->dict['formatting'];
    }

    protected function setFormatting($format)
    {
        $this->dict['formatting'] = $format;
    }

    protected function getFormatPieces( )
    {
        $post = $this->governor->post;
        $categories = get_the_terms($post->ID, 'category');
        if (!empty($categories)) {
            $result = array( );
            foreach ($categories as $category) {
                $name = $category->name;
                $href = get_category_link($category);
                $link = '<a href="' . $href . '" title="' . $name . '">' . $name . '</a>';
                $result[ ] = $link;
            }
            return array(
                sprintf($this->formatting, implode(', ', $result)),
            );
        }
        return array('Uncategorized');
    }

}
